const geoip = require("geoip-lite");
const requestIp = require("request-ip");
const { ENV } = require("../../config");
module.exports = (app) => {
    app.use((req, res, next) => {
        try {
            let clientIp = requestIp.getClientIp(req);
            if (ENV === "development") {
                clientIp = "222.190.42.0";
            }
            const { country, region, city } = geoip.lookup(clientIp);
            req.location = {
                ip: clientIp || "",
                country: country || "",
                region: region || "",
                city: city || ""
            };
            next();
        } catch (error) {
            next();
        }
    });
};
